['log', 'info', 'warn', 'error'].forEach(function(method) {
	console[method] = console[method].bind(
		console,
		new Date().toLocaleTimeString()
	);
});

//function fibo(n) {
//	return n > 1 ? fibo(n - 1) + fibo(n - 2) : 1;
//}
//var n = 8
//
//function back() {
//	if(!--n) return console.timeEnd('no thread');
//}
//console.time('no thread');
//
//process.nextTick(function() {
//	console.log(fibo(40));
//	back();
//})
//process.nextTick(function() {
//	console.log(fibo(40));
//	back();
//})
//process.nextTick(function() {
//	console.log(fibo(40));
//	back();
//})
//process.nextTick(function() {
//	console.log(fibo(40));
//	back();
//})
//
//process.nextTick(function() {
//	console.log(fibo(40));
//	back();
//})
//
//process.nextTick(function() {
//	console.log(fibo(40));
//	back();
//})
//process.nextTick(function() {
//	console.log(fibo(40));
//	back();
//})
//process.nextTick(function() {
//	console.log(fibo(40));
//	back();
//})

/*-------------------------------------*/
//function fibo(n) {
//	return n > 1 ? fibo(n - 1) + fibo(n - 2) : 1;
//}
//console.time('8 thread');
//var numThreads = 8; //创建线程池，最大数为8
//var threadPool = require('threads_a_gogo').createPool(numThreads).all.eval(fibo); //为线程池注册程序
//var i = 8;
//var cb = function(err, data) { //注册线程执行完毕的回调函数
//	console.log(data);
//	if(!--i) {
//		threadPool.destroy();
//		console.timeEnd('8 thread');
//	}
//}
//threadPool.any.eval('fibo(40)', cb); //开始向线程池中执行fibo(40)这个任务
//
//threadPool.any.eval('fibo(40)', cb);
//
//threadPool.any.eval('fibo(40)', cb);
//
//threadPool.any.eval('fibo(40)', cb);
//
//threadPool.any.eval('fibo(40)', cb);
//
//threadPool.any.eval('fibo(40)', cb);
//
//threadPool.any.eval('fibo(40)', cb);
//
//threadPool.any.eval('fibo(40)', cb);





//var start = Date.now();//获取当前时间戳
//setTimeout(function () {
//  console.log(Date.now() - start);
//  for (var i = 0; i < 3000000000; i++){//执行长循环
//  }
//}, 1000);
//setTimeout(function () {
//  console.log(Date.now() - start);
//}, 2000);



//加载tagg2的模块
var tagg = require('tagg2'); 

//子线程工作函数
//var th_func = function(){
//	var fibo =function fibo (n) {
//   		 return n > 1 ? fibo(n - 1) + fibo(n - 2) : 1;
//  	}
//	thread.end(fibo(40));
//}
//
////创建子线程,并且注册回调
//var thread = tagg.create(th_func, function(err, res){
//	if(err) throw new(err);//如果在线程中throw异常，err就会得到相应的错误
//	console.log(res);//fibo(40)的结果
//	thread.destroy();//摧毁线程
//});

var Threads = require('threads_a_gogo');//加载tagg包
function fibo(n) {//定义斐波那契数组计算函数
    return n > 1 ? fibo(n - 1) + fibo(n - 2) : 1;
}
var t = Threads.create().eval(fibo);
t.eval('fibo(35)', function(err, result) {//将fibo(35)丢入子线程运行
    if (err) throw err; //线程创建失败
    console.log('fibo(35)=' + result);//打印fibo执行35次的结果
});
console.log('not block');//打印信息了，表示没有阻塞